package com.browsesoft.baseadapter;

import java.awt.Point;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.browsesoft.Entity;

/**
 * 单表维护适配器
 */
public class HTMLBasicTableModelAdapter extends HTMLBasicTableModel {
	protected int colCount;

	protected Point TDPosition = new Point();

	/**
	 * 得到列数
	 * 
	 * @return 列数
	 */
	public int getColumnCount() {
		return this.colCount;
	}

	public void setColCount(int count) {
		this.colCount = this.enames.size() + count - 1;
	}

	/**
	 * 得到列的名称
	 * 
	 * @param index
	 *            列号
	 * @return 列的名称
	 */
	public String getColumnName(int index) {
		if (index < cnames.size()) {
			return (String) cnames.get(index);
		} else {
			return "";
		}
	}

	/**
	 * 得到某列的操作类型
	 * 
	 * @param col
	 *            col
	 * @return 类型
	 */
	public String getType(int col) {
		if (col < cnames.size()) {
			return "td";
		}
		return null;
	}

	/**
	 * 修改单元值
	 * 
	 * @param td
	 *            td
	 * @param doc
	 *            doc
	 * @param row
	 *            row
	 * @param col
	 *            col
	 */
	public void modifyCellValue(Element td, Document doc, int row, int col) {
		try {
			Entity entity = this.getOneRow(row);
			if (this.cellDisplayProcess(td, doc, row, col, entity)) {
				return;
			}
			if (col >= this.TDPosition.x && col <= this.TDPosition.y) {
				this.replace(entity, col - this.TDPosition.x, td, doc);
			} else {
				// 替换td中属性值
				this.replaceTD(td, entity);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setColType(String[] types) {
	}

	public void setTDPosition(int position) {
		this.TDPosition.x = position;
	}

	public Point getTDPosition() {
		this.TDPosition.y = this.TDPosition.x + this.enames.size() - 1;
		return this.TDPosition;
	}
}